package view.component.weapon.bug_stick
{
	import enums.main.UISize;
	
	import feathers.controls.Button;
	import feathers.controls.Screen;
	import feathers.controls.ScreenNavigator;
	import feathers.controls.ScreenNavigatorItem;
	import feathers.controls.ScrollContainer;
	import feathers.controls.TabBar;
	import feathers.data.ListCollection;
	
	import starling.animation.Tween;
	import starling.core.Starling;
	import starling.events.Event;
	
	import util.FG2FUGenerator;
	
	import view.component.weapon.bug_stick.bug.BugTypeAllStateView;
	import view.component.weapon.bug_stick.bug.BugTypePowerView;
	import view.component.weapon.bug_stick.bug.BugTypeSpeedView;
	import view.component.weapon.bug_stick.bug.BugTypeStamiView;
	import view.transition.AnimationNaviTransitionManager;
	
	
	/**
	 * 操虫棍-猎虫强化信息
	 * @author £iang
	 * 
	 */	
	public class BugStickBugView extends Screen
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 猎虫选项 */
		public var bugTabBar:TabBar;
		/** 猎虫选项滚动条容器 */
		public var bugTabSC:ScrollContainer;
		/** 猎虫强化信息导航栏 */
		public var bugNavigator:ScreenNavigator;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		/** 转场管理 */
		private var _transitManager:AnimationNaviTransitionManager;
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		override protected function initialize():void
		{
			var labelVec:Vector.<String> = new Vector.<String>();
			var dataProvider:ListCollection = new ListCollection( [] );
			var len:int;
			var i:int;
			var obj:Object;
			
			labelVec.push(
				"力量型", "体力型", "速度型", "全能型"
			);
			
			bugTabBar = new TabBar();
			bugTabBar.gap = 15 * this.dpiScale;
			len = labelVec.length;
			
			for ( i = 0; i < len; i ++ )
			{
				obj = new Object();
				obj.label = labelVec[ i ];
				dataProvider.push( obj );
			}
			
			bugTabBar.dataProvider = dataProvider;
			bugTabBar.tabFactory = mainTabFactory;
			bugTabSC = new ScrollContainer();
			this.addChild( bugTabSC );
			bugTabSC.addChild( bugTabBar );
			
			this.bugNavigator = new ScreenNavigator();
			this.addChild( bugNavigator );
			
		
			this.bugNavigator.addScreen(
				"INDEX0",
				new ScreenNavigatorItem( BugTypePowerView )
			);
			
			this.bugNavigator.addScreen(
				"INDEX1",
				new ScreenNavigatorItem( BugTypeStamiView )
			);
			
			this.bugNavigator.addScreen(
				"INDEX2",
				new ScreenNavigatorItem( BugTypeSpeedView )
			);
			
			this.bugNavigator.addScreen(
				"INDEX3",
				new ScreenNavigatorItem( BugTypeAllStateView )
			);
			
			this._transitManager = new AnimationNaviTransitionManager( bugNavigator );
			
			addListener();
		}
		
		/**
		 * 绘制函数 
		 * 
		 */		
		override protected function draw():void
		{
			bugTabSC.y = UISize.MAIN_H - UISize.MONSTER_TAB_AREA_H * this.dpiScale * 3 
				+ 40 * this.dpiScale;
			bugTabSC.x = 20 * this.dpiScale;
			bugTabSC.width = UISize.MAIN_W - 40 * this.dpiScale;
		}
		
		/**
		 * 添加侦听 
		 * 
		 */		
		private function addListener():void
		{
			bugTabBar.addEventListener( Event.CHANGE, tabBarChangeHandler );
		}
		
		/**
		 * 批量设置mainTabBar按钮 
		 * @return tabbar按钮
		 * 
		 */		
		public function mainTabFactory():Button
		{
			var button:Button = FG2FUGenerator.generateRoundRectButton(
				UISize.TAB_BUTTON_W3, UISize.TAB_BUTTON_H,
				this.dpiScale, UISize.TAB_BUTTON_H * 0.9, "small"
			);
			
			return button;
		}
		
		/**
		 * 清除导航栏 
		 * 
		 */		
		public function clearNavi():void
		{
			_transitManager.clear();
			bugNavigator.removeAllScreens();
		}
		
		/**
		 * 播放隐藏动画 
		 * 
		 */		
		public function playHideAnimation():void
		{
			var tween:Tween = new Tween( this, 0.4 );
			
			tween.animate( "alpha", 0);
			Starling.juggler.add( tween );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理tabBar改变时派发的事件 
		 * @param event tabBar改变时派发的事件 
		 * 
		 */		
		protected function tabBarChangeHandler( event:Event ):void
		{
			if ( bugTabBar.selectedIndex >= 0 )
				this.bugNavigator.showScreen( "INDEX" + bugTabBar.selectedIndex );
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构函数 
		 * 
		 */		
		override public function dispose():void
		{
			Starling.juggler.removeTweens( this );
			
			var i:int;
			var button:Button;
			
			for ( i = 0; i < bugTabBar.numChildren; i ++ )
			{
				if ( bugTabBar.getChildAt( i ) is Button )
				{
					button = bugTabBar.getChildAt( i ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			bugTabSC.dispose(); bugTabSC = null;
			
			bugNavigator.dispose();
			bugNavigator = null;
			_transitManager = null;
			super.dispose();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function BugStickBugView()
		{
			super();
		}
	}
}